use axum::{
    body::Body,
    http::{Response, StatusCode},
    response::IntoResponse,
};

use crate::router;

#[derive(Debug)]
pub enum AuthError {
    WrongCredentials,
    MissingCredentials,
    TokenCreation,
    InvalidToken,
    ExpiredToken,
}

impl IntoResponse for AuthError {
    fn into_response(self) -> Response<Body> {
        match self {
            AuthError::WrongCredentials => router::resp::RespVO::<()>::from_error(
                Some(StatusCode::UNAUTHORIZED.as_u16()),
                "Wrong credentials".to_owned(),
                None,
            )
            .into_response(),
            AuthError::MissingCredentials => router::resp::RespVO::<()>::from_error(
                Some(StatusCode::BAD_REQUEST.as_u16()),
                "Missing credentials".to_owned(),
                None,
            )
            .into_response(),
            AuthError::TokenCreation => router::resp::RespVO::<()>::from_error(
                Some(StatusCode::INTERNAL_SERVER_ERROR.as_u16()),
                "Token creation error".to_owned(),
                None,
            )
            .into_response(),
            AuthError::InvalidToken => router::resp::RespVO::<()>::from_error(
                Some(StatusCode::BAD_REQUEST.as_u16()),
                "Invalid token".to_owned(),
                None,
            )
            .into_response(),
            AuthError::ExpiredToken => router::resp::RespVO::<()>::from_error(
                Some(StatusCode::BAD_REQUEST.as_u16()),
                "Token expired".to_owned(),
                None,
            )
            .into_response(),
        }
    }
}
